SyntaxError: The requested module 'node:fs/promises' does not provide an export named 'constants'
栏目:
Vue
发布时间:2025-06-18
使用 vite 构建 vue项目,遇到如下报错:
import fsp, { constants as constants$3 } from 'node:fs/promises';
^^^^^^^^^
SyntaxError: The requested module 'node:fs/promises' does not provide an export named 'constants'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:179:5)
at async Loader.import (node:internal/modules/esm/loader:178:24)
解决方案:
升级 node.js 版本,亲测 18.16.1 版本可用。
$ node -v
v16.6.0
tenglei@Mac vite$ sudo n
Password:
copying : node/18.16.1
installed : v18.16.1 (with npm 9.5.1)
tenglei@Mac vite$ npm run dev
> vite@0.0.0 dev
> vite
VITE v6.3.5 ready in 352 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h + enter to show help
本文地址:https://www.tides.cn/p_vue-vite- syntaxError-the-requested-module-node-fs-promises-does-not-provide-an-export-named-constants